/*
 * @lc app=leetcode.cn id=119 lang=javascript
 *
 * [119] 杨辉三角 II
 */

// @lc code=start
/**
 * @param {number} rowIndex
 * @return {number[]}
 */
var getRow = function(rowIndex) {
    rowIndex = rowIndex + 1
    function sumArr(arr) {
        let resArr = []
        arr.forEach((e,i) => {
            if (i !== arr.length - 1) {   
                resArr.push(e + arr[i + 1])
            }
        })
        return resArr
    }
    let arr = [[1]]
    if (rowIndex === 1) {
        return arr
    }
    arr.push([1,1])
    for (let index = 2; index < rowIndex; index++) {
        let row = arr[index] = []
        row.push(1)
        row.push(...sumArr(arr[index - 1]))
        row.push(1)
    }
    return arr[rowIndex - 1]
};
// @lc code=end

